package com.lsyw.intergrate.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.util.StringUtils;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.lsyw.intergrate.entity.common.PageInfo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lsyw.intergrate.common.Result;
import org.springframework.util.CollectionUtils;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import com.lsyw.intergrate.service.JcMassifFactorValueService;
import com.lsyw.intergrate.entity.JcMassifFactorValue;
import java.util.*;
import io.swagger.annotations.Api;
import lombok.Data;

import org.springframework.stereotype.Controller;

/**
 * <p>
 * 监测数据表 前端控制器
 * </p>
 *
 * @author 刘磊
 * @since 2023-12-19
 */
@Api(tags ="监测数据表"  )
@RestController
@RequestMapping("/jc-massif-factor-value")
    public class JcMassifFactorValueController {


@Autowired
private JcMassifFactorValueService jcMassifFactorValueService;


/**
* 通过id查询
*/
@GetMapping("/get-by-id")
public  Result getById(String id){
        return Result.successResult(jcMassifFactorValueService.getById(id));
        }

/**
* 新增
*/
@PostMapping("/save")
public Result save(@RequestBody JcMassifFactorValue jcMassifFactorValue){
    jcMassifFactorValueService.save(jcMassifFactorValue);
        return Result.successResult(null);
        }

    /**
    * 通过id删除
    */
    @GetMapping("/delete-by-id/{id}")
    public Result delete(@PathVariable(value = "id") String ids){
            String[]idsStrs=ids.split(",");
            for(String id:idsStrs){
        jcMassifFactorValueService.removeById(Long.parseLong(id));
            }
            return Result.successResult(null);
            }

/**
* 修改
*/
@PostMapping("/update")
public Result updateById(@RequestBody JcMassifFactorValue jcMassifFactorValue){
    jcMassifFactorValueService.updateById(jcMassifFactorValue);
        return Result.successResult(null);
        }


/**
* 查询列表
*/
@PostMapping("/list")
public Result list(@RequestBody JcMassifFactorValueReqVo jcMassifFactorValue ){
final LambdaQueryWrapper<JcMassifFactorValue> lambda=new QueryWrapper<JcMassifFactorValue>().lambda();
        this.buildCondition(lambda,jcMassifFactorValue);
        return Result.successResult(jcMassifFactorValueService.list(lambda));
        }

/**
* 分页查询
*/
@PostMapping("/page")
public Result page(@RequestBody PageInfo pageInfo){
        Page<JcMassifFactorValue> page=new Page<>();
        page.setSize(pageInfo.getPageSize());
        page.setCurrent(pageInfo.getPageNum());
final LambdaQueryWrapper<JcMassifFactorValue> lambda=new QueryWrapper<JcMassifFactorValue>().lambda();
        //TODO 自己的查询逻辑
        return Result.successResult(this.jcMassifFactorValueService.page(page,lambda));
        }


/**
* 构造查询条件
* @param lambda
* @param param
*/
private void buildCondition(LambdaQueryWrapper<JcMassifFactorValue> lambda, JcMassifFactorValueReqVo param){
                if(!StringUtils.isEmpty(param.getId())){
                lambda.eq(JcMassifFactorValue::getId,param.getId());
                }
                if(!StringUtils.isEmpty(param.getMassifId())){
                lambda.eq(JcMassifFactorValue::getMassifId,param.getMassifId());
                }
                if(!StringUtils.isEmpty(param.getJcFactorId())){
                lambda.eq(JcMassifFactorValue::getJcFactorId,param.getJcFactorId());
                }
                if(!StringUtils.isEmpty(param.getGmtCreateUser())){
                lambda.eq(JcMassifFactorValue::getGmtCreateUser,param.getGmtCreateUser());
                }
                if(!CollectionUtils.isEmpty(param.getGmtCreateList())){
                lambda.ge(JcMassifFactorValue::getGmtCreate,param.getGmtCreateList().get(0));
                lambda.le(JcMassifFactorValue::getGmtCreate,param.getGmtCreateList().get(1));
                }
                if(!StringUtils.isEmpty(param.getGmtModifiedUser())){
                lambda.eq(JcMassifFactorValue::getGmtModifiedUser,param.getGmtModifiedUser());
                }
                if(!CollectionUtils.isEmpty(param.getGmtModifiedList())){
                lambda.ge(JcMassifFactorValue::getGmtModified,param.getGmtModifiedList().get(0));
                lambda.le(JcMassifFactorValue::getGmtModified,param.getGmtModifiedList().get(1));
                }
                if(!StringUtils.isEmpty(param.getDelFlag())){
                lambda.eq(JcMassifFactorValue::getDelFlag,param.getDelFlag());
                }
                if(!StringUtils.isEmpty(param.getFactorValue())){
                lambda.eq(JcMassifFactorValue::getFactorValue,param.getFactorValue());
                }
                if(!StringUtils.isEmpty(param.getDeviceNo())){
                lambda.eq(JcMassifFactorValue::getDeviceNo,param.getDeviceNo());
                }
                if(!StringUtils.isEmpty(param.getCn())){
                lambda.eq(JcMassifFactorValue::getCn,param.getCn());
                }
                if(!StringUtils.isEmpty(param.getJcMassifFactorValueLog())){
                lambda.eq(JcMassifFactorValue::getJcMassifFactorValueLog,param.getJcMassifFactorValueLog());
                }
        lambda.orderBy(true,false, JcMassifFactorValue::getId);
        }


/**
 * 请求model
 */
@Data
    @AllArgsConstructor
private static class JcMassifFactorValueReqVo extends JcMassifFactorValue {
            private List<String> gmtCreateList; // 创建时间起止
            private List<String> gmtModifiedList; // 更新时间起止
}


}
